package cn.edu.zafu.bigdata.x.bd121.staticdemo;

/**
 * static静态关键字demo
 *
 * @author 202211090121
 */
public class StaticDemo {

    // 静态初始化块
    static {
        System.out.println("Static block executed");
        // 初始化count为0
        count = 0;
    }

    // 实例初始化块
    {
        System.out.println("Instance block executed");
        this.id = count;
        count++;
    }

    /**
     * 用于记录已被实例化的对象的数量的静态变量
     */
    public static int count;

    /**
     * 实例化对象的id
     */
    private int id;

    /**
     * 构造函数，输出构造函数的调用信息
     */
    public StaticDemo() {
        System.out.printf("Constructor executed for ID:%d\n", this.id);
    }

    /**
     * 展示实例化对象数
     */
    public static void displayCount() {
        System.out.printf("当前实例化了%d个对象\n", count);
    }
}
